﻿package com.toncen.samepms.system.domain;

import com.toncen.samepms.common.AbstractDomain;
import com.toncen.samepms.common.AbstractJob;
import com.sky.common.lang.ClassUtils;
import com.sky.common.string.StringUtils;
import com.sky.dataimport.DynamicCellDataCell;
import com.sky.dataimport.DynamicCellDataRow;
import com.sky.dataimport.DynamicRowDataCell;
import com.sky.dataimport.DynamicRowDataRow;
import com.sky.dataimport.StaticDataCell;
import com.sky.dataimport.StaticDataRow;

/**
 * 描述：计划任务表SYSTEM_SCHEDULER_JOB的domain文件
 * 
 * @author tch
 */
@DynamicRowDataRow(title = "动态行计划任务", sheetIndex = 1, startRowIndex = 2, startCellIndex = 1, inserted = false)
@DynamicCellDataRow(title = "动态列计划任务", sheetIndex = 1, startRowIndex = 2, startCellIndex = 2, inserted = false)
@StaticDataRow(title = "静态行列计划任务", sheetIndex = 1)
public class SchedulerJob extends AbstractDomain {
	/**
	 * 序列号
	 */
	private static final long serialVersionUID = 1341973942649L;

	/**
	 * 任务名
	 */
	@StaticDataCell(rowIndex = 1, cellIndex = 1, title = "任务名")
	@DynamicRowDataCell(cellIndex = 1, title = "任务名", require = false)
	@DynamicCellDataCell(rowIndex = 1, title = "任务名", require = false)
	private String jobName;

	/**
	 * 任务类
	 */
	@StaticDataCell(rowIndex = 2, cellIndex = 2, title = "任务类")
	@DynamicRowDataCell(cellIndex = 2, title = "任务类", require = false)
	@DynamicCellDataCell(rowIndex = 2, title = "任务类", require = false)
	private String jobClass;

	/**
	 * 时间设置
	 */
	@StaticDataCell(rowIndex = 3, cellIndex = 3, title = "时间设置")
	@DynamicRowDataCell(cellIndex = 3, title = "时间设置", require = false)
	@DynamicCellDataCell(rowIndex = 3, title = "时间设置", require = false)
	private String time;

	public SchedulerJob() {
		super();
	}

	/**
	 * @return the jobName
	 */
	public String getJobName() {
		return jobName;
	}

	/**
	 * @param jobName
	 *            the jobName to set
	 */
	public void setJobName(String jobName) {
		this.jobName = jobName;
	}

	/**
	 * @return the jobClass
	 */
	public String getJobClass() {
		return jobClass;
	}

	/**
	 * @param jobClass
	 *            the jobClass to set
	 */
	public void setJobClass(String jobClass) {
		this.jobClass = jobClass;
	}

	/**
	 * @return the time
	 */
	public String getTime() {
		return time;
	}

	/**
	 * @param time
	 *            the time to set
	 */
	public void setTime(String time) {
		this.time = time;
	}

	/**
	 * @return
	 * @throws Exception
	 */
	public AbstractJob getJob() throws Exception {
		if (StringUtils.isEmpty(this.getJobClass())) {
			throw new Exception("计划任务任务类必须设置，请与系统管理员联系！");
		}
		Object job = ClassUtils.newInstance(this.getJobClass());
		if (job instanceof AbstractJob) {
			return (AbstractJob) job;
		} else {
			throw new Exception("计划任务【" + this.getJobClass() + "】必须继承【" + AbstractJob.class.getName() + "】，请与系统管理员联系！");
		}

	}
}
